//
//  PSCell.m
//  Btpin
//
//  Created by Vic on 2019/3/12.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "PSCell.h"

@implementation PSCell

//- (instancetype)initWithFrame:(CGRect)frame title:(nullable NSString *)title text:(nullable NSString *)text placeholder:(nullable NSString *)placeholder cellType:(PSCellType)cellType tap:(void (^)(void))tap
- (instancetype)initWithFrame:(CGRect)frame title:(nullable NSString *)title text:(nullable NSString *)text placeholder:(nullable NSString *)placeholder cellType:(PSCellType)cellType {
    self = [super initWithFrame:frame];
    if (self) {
        [self initUITitle:title text:text placeholder:placeholder cellType:cellType];
//        self.tap = tap;
    }
    return self;
}
- (void)initUITitle:(nullable NSString *)title text:(nullable NSString *)text placeholder:(nullable NSString *)placeholder cellType:(PSCellType)cellType {
    UILabel *titleLbl = [UIToolsControl initLabelWithFrame:CGRectMake(3*Scale, 8*Scale, self.frame.size.width-10*Scale, 20*Scale) text:title textColor:THEMECOLOR_OF_TEXT_333333 font:Font_12];
    [self addSubview:titleLbl];
    
    self.textField = [UIToolsControl initTextFieldWithFrame:CGRectMake(StartX(titleLbl), EndY(titleLbl), ViewWidth(titleLbl)-15*Scale, 40*Scale) placeholder:placeholder secureTextEntry:NO font:Font_17 padding:NO];
    self.textField.text = text;
    [self addSubview:self.textField];
    
    UIImageView *imgView = [UIToolsControl initImageViewWithFrame:CGRectMake(self.frame.size.width-8*Scale, 30*Scale, 7*Scale, 13*Scale) imageName:@"jiantou_right"];
    imgView.userInteractionEnabled = NO;
    imgView.hidden = YES;
    [self addSubview:imgView];
    
    
    switch (cellType) {
        case PSCellTypeOfDefault: {
            
        } break;
        case PSCellTypeOfReadonly: {
            UIView *view = [UIToolsControl initViewWithFrame:self.bounds backgroundColor:COLOR_OF_CLEAR];
            [self addSubview:view];
            UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesClick)];
            [self addGestureRecognizer:tapGes];
        } break;
        case PSCellTypeOfWriteonly: {
            
        } break;
        case PSCellTypeOfReadwrite: {
            
        } break;
        case PSCellTypeOfIndicator: {
            imgView.hidden = NO;
            UIView *view = [UIToolsControl initViewWithFrame:self.bounds backgroundColor:COLOR_OF_CLEAR];
            [self addSubview:view];
            UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesClick)];
            [self addGestureRecognizer:tapGes];
        } break;
        default:
            break;
    }
    
    [self borderColor:THEMECOLOR_OF_TEXT_cccccc borderWidth:lineH borderType:BorderSideTypeBottom];
}
- (void)tapGesClick {
    self.tap();
}

@end
